//
//  SMHMyOrderViewController.swift
//  SMHCommerce
//
//  Created by lvzhao on 2020/6/4.
//  Copyright © 2020 lvzhao. All rights reserved.
//

import UIKit

class SMHMyOrderViewController: LZBaseViewController,MFPageContentViewDelegate,MFPageTitleViewDelegate{

    

    var index :Int?
    var type :String?
    var titles :[String]?
    var pageContentView :MFPageContentView?

    override func viewDidLoad() {
        super.viewDidLoad()
        switch type {
           case "upgrade":
               self.title = "解锁订单"
           case "merchant":
               self.title = "零售订单"
           default:
               self.title = "我的订单"
        }
        
        titles = ["全部","待付款","待发货","待收货","已完成"]
        
        setupUI()
    }
    
    //MARK:setupUI
    func setupUI() {
    
        var childControllers = [UIViewController]()
        for idex in 0..<titles!.count
        {
            let vc = SMHOrderViewController.init(status: idex)
            vc.type = type
            childControllers.append(vc)
            let pageContentViewY = pageTitleView.frame.maxY
            pageContentView = MFPageContentView(frame: CGRect(x: 0, y: pageContentViewY, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - pageContentViewY - CGFloat(kNavHeight)), parentVC: self, childVCs: childControllers)
            pageContentView!.pageContentViewDelegate = self
        }
        
        view.addSubview(self.pageTitleView)
        view.addSubview(pageContentView!)
        
        
        self.pageTitleView.selectedIndex = 3
       
    }

    //MARK:MFPageContentViewDelegate
    func pageContentViewScroll(progress: CGFloat, originalIndex: Int, targetIndex: Int) {
        
        self.pageTitleView.setPageTitleView(progress: progress, originalIndex: originalIndex, targetIndex: targetIndex)

    }
    
    //MARK:MFPageTitleViewDelegate

    func selectedIndexInPageTitleView(pageTitleView: MFPageTitleView, selectedIndex: Int){
        
        pageContentView!.setPageContentViewCurrentIndex(currentIndex: selectedIndex)
    }

    
    lazy var pageTitleView : MFPageTitleView = {
        let config = MFPageTitleViewConfig()
        config.titleColor = UIColorFromHex(rgbValue: 0x868686)
        config.titleSelectedColor = UIColorFromHex(rgbValue: 0x363636)
        config.titleFont = ktextFont(size: 16)
        config.titleSelectFont = ktextFont(size: 16)
        config.indicatorColor = UIColorFromHex(rgbValue: (0xFF661B))

        let pageTitleView = MFPageTitleView.init(frame: CGRect(x: 0, y: 0.5, width: kScreenWidth, height: 45), titles: titles!, config: config)
        pageTitleView.pageTitleViewDelegate = self
        return pageTitleView
    }()
    

    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */
    /**
    import UIKit

    class VCTwo: UIViewController {
        
        
        
        private lazy var pageTitleView: MFPageTitleView = {
            let config = MFPageTitleViewConfig()
            config.titleColor = colorWithRGB(r: 43, g: 43, b: 43)
            config.titleSelectedColor = colorWithRGB(r: 211, g: 0, b: 0)
            config.titleFont = UIFont.systemFont(ofSize: 14, weight: .regular)
            config.indicatorColor = colorWithRGB(r: 211, g: 0, b: 0)
            let pageTitleView = MFPageTitleView(frame: CGRect(x: 0, y: navHeight, width: SCREEN_WIDTH, height: 41), titles: ["关注", "推荐", "热点", "世界杯","全部"], config: config)
            pageTitleView.pageTitleViewDelegate = self
            return pageTitleView
        }()
        
        private lazy var pageContentView: MFPageContentView = {
            var childControllers = [UIViewController]()
            for _ in 0..<5 {
                let vc = UIViewController()
                let red: CGFloat = CGFloat(arc4random() % 256)
                let green: CGFloat = CGFloat(arc4random() % 256)
                let blue: CGFloat = CGFloat(arc4random() % 256)
                vc.view.backgroundColor = UIColor(red: red / 255.0, green: green / 255.0, blue: blue / 255.0, alpha: 1.0)
                childControllers.append(vc)
            }
            
            let pageContentViewY = pageTitleView.frame.maxY
            let pageContentView = MFPageContentView(frame: CGRect(x: 0, y: pageContentViewY, width: SCREEN_WIDTH, height: SCREEN_HEIGHT-pageContentViewY), parentVC: self, childVCs: childControllers)
            pageContentView.pageContentViewDelegate = self
            return pageContentView
        }()

        override func viewDidLoad() {
            super.viewDidLoad()
            view.backgroundColor = UIColor.white
            view.addSubview(pageTitleView)
            view.addSubview(pageContentView)
        }

    }

    extension VCTwo: MFPageTitleViewDelegate, MFPageContentViewDelegate {
        func selectedIndexInPageTitleView(pageTitleView: MFPageTitleView, selectedIndex: Int) {
            self.pageContentView.setPageContentViewCurrentIndex(currentIndex: selectedIndex)
        }
        func pageContentViewScroll(progress: CGFloat, originalIndex: Int, targetIndex: Int) {
            self.pageTitleView.setPageTitleView(progress: progress, originalIndex: originalIndex, targetIndex: targetIndex)
        }
    }

    */
}
